package com.线程池;

import lombok.SneakyThrows;

import java.util.concurrent.*;

public class ThreadPoolDemo02 {
    @SneakyThrows
    public static void main(String[] args) {
        MyCallable myCallable = new MyCallable();

        //创建线程池
        ExecutorService pool = new ThreadPoolExecutor(
                3,//正事工三个
                5,//员工最多是5个
                6, TimeUnit.SECONDS,//临时员工存活的最大时间 6s
                new ArrayBlockingQueue<>(5),//队列 沙发做着等着线程处理完的任务
                Executors.defaultThreadFactory(),//指定线程工厂创建线程
                new ThreadPoolExecutor.AbortPolicy()//对于处理不了的线程 的处理方式
        );

        //处理线程
        Future<String> submit1 = pool.submit(myCallable);
        Future<String> submit2= pool.submit(myCallable);
        Future<String> submit3 = pool.submit(myCallable);
        Future<String> submit4 = pool.submit(myCallable);

        //得到返回结果
        String s1 = submit1.get();
        String s2 = submit2.get();
        String s3 = submit3.get();
        String s4 = submit4.get();

        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);

    }
}
